//
//  XKAuthoLoginController.m
//  xk100
//
//  Created by xiaokang on 2017/7/3.
//  Copyright © 2017年 xiaokang. All rights reserved.
//

#import "XKAuthoLoginController.h"

@interface XKAuthoLoginController ()
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) UIImageView *pcImageView;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) UIButton *confirmButton;
@property (nonatomic, strong) UIButton *cancelButton;
@end

@implementation XKAuthoLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor yg_colorWithHexString:@"#f3f3f6"];
    
    _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _closeButton.titleLabel.font = [UIFont systemFontOfSize:18*Scale_W];
    [_closeButton setTitle:@"关闭" forState:UIControlStateNormal];
    [_closeButton setTitleColor:[UIColor yg_colorWithHexString:@"#00b900"] forState:UIControlStateNormal];
    [_closeButton addTarget:self action:@selector(cancelAuthoLogonEnent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_closeButton];
    [_closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(30*Scale_W);
        make.right.mas_equalTo(self.view).offset(-20*Scale_W);
    }];
    
    _pcImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pc_desktop_image"]];
    [self.view addSubview:_pcImageView];
    [_pcImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(180*Scale_W);
        make.size.mas_equalTo(CGSizeMake(137*Scale_W, 105*Scale_W));
        make.centerX.mas_equalTo(self.view);
    }];
    
    _tipLabel = [UILabel getLabWithText:@"PC端账号登录授权" textFont:Font_21 textColor:[UIColor blackColor] textAlignment:NSTextAlignmentCenter];
    [self.view addSubview:_tipLabel];
    [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(_pcImageView.mas_bottom).offset(20*Scale_W);
    }];
    
    
    _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _cancelButton.titleLabel.font = [UIFont systemFontOfSize:17*Scale_W];
    [_cancelButton setTitle:@"取消登录" forState:UIControlStateNormal];
    [_cancelButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_cancelButton addTarget:self action:@selector(cancelAuthoLogonEnent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_cancelButton];
    [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view).offset(-60*Scale_W);
        make.centerX.mas_equalTo(self.view);
    }];
    
    
    _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _confirmButton.layer.borderWidth = 1;
    _confirmButton.layer.borderColor = [UIColor yg_colorWithHexString:@"#00b900"].CGColor;
    _confirmButton.layer.cornerRadius = 5;
    _confirmButton.layer.masksToBounds = YES;
    _confirmButton.titleLabel.font = [UIFont systemFontOfSize:20*Scale_W];
    [_confirmButton setTitle:@"登录" forState:UIControlStateNormal];
    [_confirmButton setTitleColor:[UIColor yg_colorWithHexString:@"#00b900"] forState:UIControlStateNormal];
    [_confirmButton addTarget:self action:@selector(confirmAuthoLogonEnent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_confirmButton];
    [_confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_cancelButton.mas_top).offset(-44*Scale_W);
        make.size.mas_equalTo(CGSizeMake(160*Scale_W, 44*Scale_W));
        make.centerX.mas_equalTo(self.view);
    }];
    
}


#pragma mark - 取消登录授权
- (void)cancelAuthoLogonEnent:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 确认登录授权
- (void)confirmAuthoLogonEnent:(UIButton *)sender {
    [SVProgressHUD show];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD showSuccessWithStatus:@"授权成功!"];
    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self cancelAuthoLogonEnent:nil];
    });
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
